Skip to content

Implement lazy loading for category examples and improve type safety#36

Merged
Null000 merged 1 commit intomainfrom
claude/improve-performance-KkuhD
Feb 23, 2026
Merged

Implement lazy loading for category examples and improve type safety#36
Null000 merged 1 commit intomainfrom
claude/improve-performance-KkuhD

Conversation

@Null000
Copy link
Copy Markdown
Owner

@Null000 Null000 commented Feb 23, 2026

Summary

This PR optimizes the category examples loading by implementing lazy initialization and improves type safety throughout the codebase by replacing any types with proper TypeScript types.

Key Changes

  • Lazy load category examples: Examples are now generated only when a category group is opened, rather than being created upfront for all categories. This improves initial page load performance.

    • Examples container is created empty initially
    • Examples are populated on the first toggle event when a group is opened
    • Auto-opened groups (with checked items) trigger example generation immediately
  • Improved type safety:

    • Changed solved as any[] to solved as string[] in index.ts
    • Changed currentProblem: any to currentProblem: Problem in practice.ts
    • Replaced const dict: any = {} with const dict: Partial<Record<Category, string>> = {} in common.ts with proper type assertion
  • Code cleanup:

    • Removed debug console.log() statement from practice.ts
    • Updated comment to clarify that examples container is populated lazily

Implementation Details

The lazy loading is implemented by:

  1. Creating an empty .category-examples div for each category
  2. Attaching a toggle event listener to the group's <details> element
  3. On toggle, querying for empty example containers and populating them with 3 random problems
  4. Manually dispatching the toggle event for auto-opened groups to ensure examples are generated

https://claude.ai/code/session_01HG9GdKzqLikbHeTm98p5p8

- Lazy-load category example problems: defer generation until the
  category group is expanded, avoiding ~84 upfront problem generations
- Remove debug console.log that serialized every problem to the console
- Replace `any` types with proper types (Partial<Record<...>> in
  common.ts, Problem in practice.ts, string[] in index.ts)

https://claude.ai/code/session_01HG9GdKzqLikbHeTm98p5p8
@Null000 Null000 merged commit c1d0b20 into main Feb 23, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants